package cn.bdqn.controller;

import cn.bdqn.mapper.Ebook_entryMapper;
import cn.bdqn.pojo.Ebook_entry;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class TestController {

    @Resource
    private Ebook_entryMapper e;


    @RequestMapping("/cs")
    @ResponseBody
    public String aa(){

        return "测试";
    }


    //查所有
    @GetMapping("/csy")
    @ResponseBody
    public Object getUserList(Integer categoryid,Integer page,Integer limit){
        //Integer startNum=(page-1)*limit;
        //获取总条数
        //Integer getCount=e.totalCountByCategoryId(categoryid,page,limit);
        //获取每页的显示内容
        List<Ebook_entry> userList = e.querybookEntryList(0,0,10);
        //      组装数据，注意map中的key的命名
        Map<String,Object> result = new HashMap<>();
        result.put("data",userList);
        result.put("code",0);
        result.put("count",10);
        return result;
    }


    @GetMapping("/login")
    public String jg11(){
        return "login";
    }

    @GetMapping("/add")
    public String jg111(){
        return "add";
    }

    //  保存方法
    @RequestMapping("/ss")
    @ResponseBody
    public Object saveUser(Ebook_entry books) {
        Map<String,Object> result = new HashMap<>();
        int i = e.tj(books);
        result.put("code",0);
        result.put("mark",i);
        return result;
    }


    //  删除方法
    @RequestMapping("/sc")
    @ResponseBody
    public Object saveUse1r(int id) {
        Map<String,Object> result = new HashMap<>();
        int i = e.sc(id);
        result.put("code",0);
        result.put("mark",i);
        return result;
    }

    //  修改方法
    @RequestMapping("/xg")
    @ResponseBody
    public Object saveUse11r(Ebook_entry id) {
        Map<String,Object> result = new HashMap<>();
        int i = e.xg(id);
        result.put("code",0);
        result.put("mark",i);
        return result;
    }

}

